let OSS = require('ali-oss');
export function aliossUpload(file, ossConfig) {
    return new Promise(function (resolve, reject) {
        if (!file) {
            reject('缺失file!');
            return;
        }
        if (!ossConfig.region || !ossConfig.accessKeyId || !ossConfig.accessKeySecret || !ossConfig.bucket) {
            reject('上传参数缺失!');
            return;
        }
        const client = new OSS(ossConfig);
        var uploadPath = new Date().getTime() + '.' + file.name.split(".")[file.name.split(".").length - 1];
        var localFile = file;
        client.put(uploadPath, localFile).then(function (response) {
            console.log('aliossUpload response', response)
            resolve(response)
        })

    });
}

export function aliossRemove(url, ossConfig) {
    return new Promise(function (resolve, reject) {
        var fileName = url.split('/').pop();
        if (!fileName) {
            reject('缺失fileName!');
            return;
        }
        if (!ossConfig.region || !ossConfig.accessKeyId || !ossConfig.accessKeySecret || !ossConfig.bucket) {
            reject('上传参数缺失!');
            return;
        }
        const client = new OSS(ossConfig);
        client.delete(fileName).then(function (response) {
            console.log('aliossDel response', response)
            resolve(true)
        })

    });
}
